package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TbCar;
import com.ruoyi.system.service.ITbCarService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * addcarController
 * 
 * @author ruoyi
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/car")
public class TbCarController extends BaseController
{
    @Autowired
    private ITbCarService tbCarService;

    /**
     * 查询addcar列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbCar tbCar)
    {
        startPage();
        List<TbCar> list = tbCarService.selectTbCarList(tbCar);
        return getDataTable(list);
    }

    /**
     * 导出addcar列表
     */
    @RequiresPermissions("system:car:export")
    @Log(title = "addcar", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCar tbCar)
    {
        List<TbCar> list = tbCarService.selectTbCarList(tbCar);
        ExcelUtil<TbCar> util = new ExcelUtil<TbCar>(TbCar.class);
        util.exportExcel(response, list, "addcar数据");
    }

    /**
     * 获取addcar详细信息
     */
    @RequiresPermissions("system:car:query")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Integer carId)
    {
        return success(tbCarService.selectTbCarByCarId(carId));
    }

    /**
     * 新增addcar
     */
    @RequiresPermissions("system:car:add")
    @Log(title = "addcar", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCar tbCar)
    {
        return toAjax(tbCarService.insertTbCar(tbCar));
    }

    /**
     * 修改addcar
     */
    @RequiresPermissions("system:car:edit")
    @Log(title = "addcar", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCar tbCar)
    {
        return toAjax(tbCarService.updateTbCar(tbCar));
    }

    /**
     * 删除addcar
     */
    @RequiresPermissions("system:car:remove")
    @Log(title = "addcar", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Integer[] carIds)
    {
        return toAjax(tbCarService.deleteTbCarByCarIds(carIds));
    }


}
